﻿using UnityEngine;
using System.Collections;

public class OnClickEnemy : OnClick {
    PlayerManager Player;
    Renderer ThisGORenderer;
    Stats stats;

    void Start()
    {
        stats = gameObject.GetComponent<Stats>();
        ThisGORenderer = gameObject.GetComponentInChildren<Renderer>();
        Player = GameObject.FindGameObjectWithTag("Player").GetComponent<PlayerManager>();
    }
	protected override void WindowPopup(int windowID)
    {
        base.WindowPopup(windowID);
        if (Touched)
        {
            if (Vector3.Distance(transform.position, Player.gameObject.transform.position) < Player.stats.AttackRange)
            {
                GUI.DrawTexture(new Rect(0, 0, 100, 100), Attack);
                if (GUI.Button(new Rect(0, 0, 100, 100), "Attack", style)&&Player.Turn)
                {
                    if (Player.GetComponent<Inventory>().equipedGun.Ammmo > 0 || Player.GetComponent<Inventory>().equipedGun.type == Item.TypeOfItem.DefaultGun)
                    {
                        stats.RecibeDamage(Player.stats.Damage);
                        Player.Shoot();
                        ThisGORenderer.material.color = Color.white;
                        Touched = false;
                        Player.Turn = false;
                    }
                    else {
                        Player.Shoot();
                    }
                }
                GUI.DrawTexture(new Rect(50, 100, 100, 100), Cancel);
                if (GUI.Button(new Rect(50, 100, 100, 100), "Cancel", style))
                {
                    Touched = false;
                    ThisGORenderer.material.color = Color.white;
                }
            }
            else
            {
                Touched = false;
                ThisGORenderer.material.color = Color.white;
            }
        }
    }
    protected override void OnGUI()
    {
        base.OnGUI();
        if (Touched)
        {
			windowRect = GUI.Window(0, new Rect(screenPos.x - 75, screenPos.y - 100, 150, 200), WindowPopup, "", style);
        }
    }
    protected override void OnMouseDown()
    {
        base.OnMouseDown();
    }
    protected override void OnMouseEnter()
    {
        base.OnMouseEnter();
    }
    protected override void OnMouseExit()
    {
        base.OnMouseExit();
    }
}
